﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.LunarSocket;
using ServerBase.Protocol;
using UtilLib;
using static ServerBase.Config.Conf;
using static ServerBase.Service.BaseDispatch;
using static UtilPublic.Redis.ServerRedis;
using ServerGame.Service;
using System.Collections.Generic;
using UtilPublic.ServerLoger;
using ServerBase.Service;
using ServerBase.Config;
using static ServerGame.Service.Dispatcher;
using ServerBase.Client;
using System;
using ServerPublic.Data;
using ServerGame.GameObject;
using static UtilPublic.Serialization.Jsh;
using ServerPublic.DataBaseMysql;
using UtilPublic.ApiDispatcher;
using ServerGame.Data;

namespace ServerGame.Manager
{
    public partial class DispatcherMsg
    {
        [ApiDpPro((short)EProtocolId.C2G_SKILL_LIST, "技能列表")]
        public short OnSkillList()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnSkillList();

            player.GetInfo(Rsp.DictSkill);
            player.GetInfo(Rsp.DictUsage);
            player.GetInfo(Rsp.ListSkill);
            player.GetInfo(Rsp.ListUsage);

            return Send(Rsp);
        }
        [ApiDpPro((short)EProtocolId.C2G_SKILL_LEVELUP, "技能升级")]
        public short OnSkillLevelup()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnSkillLevelup();

            Rsp.SkillId = Req.SkillId;

            var SkillLv = player.Skill(Req.SkillId);
            if (SkillLv <= 0)
            {
                Rsp.MessageFail("您还没有学会这项技能"); return Send(Rsp);
            }
            var potneed = SkillMgr.GetPotLevelup(SkillLv);
            if (!player.ValueCheck(EAwardType.潜能, potneed))
            {
                Rsp.Result = EProtocolResult.潜能不足; return Send(Rsp);
            }

            player.ValueUse(EAwardType.潜能, potneed, EActionSource.技能升级);
            var lvnew = SkillLv + 1;
            player.Skill(Req.SkillId, lvnew);

            Rsp.Skill = new CLS_InfoSkill() { Id = Req.SkillId, Level = lvnew };

            player.InfoAll();
            return Send(Rsp);
        }
        [ApiDpPro((short)EProtocolId.C2G_SKILL_USAGEUSE, "激发")]
        public short OnSkillUsageUse()
        {
            var player = (Player)ThisSession.SessionObj;
            (var Req, var Rsp) = ThisReq.Body.OnSkillUsageUse();

            Rsp.Usage = Req.Usage;
            Rsp.Skill = Req.Skill;

            if (!ConfListUsage.Contains(Req.Usage))
            {
                Rsp.MessageFail("技能激发错误"); return Send(Rsp);
            }
            if (Req.Skill.IsNullOrEmpty() || Req.Skill == "无")
            {
                player.DaCommon.DictUsage[Req.Usage] = "无";
            }
            else
            {
                if (!player.DaCommon.DictSkill.ContainsKey(Req.Skill))
                {
                    Rsp.MessageFail("您还没有学会这项技能"); return Send(Rsp);
                }
                if (!ConfSkill.TryGetValue(Req.Skill, out var confskill))
                {
                    Rsp.MessageFail("没有这项技能"); return Send(Rsp);
                }
                if (!confskill.Usage.Contains(Req.Usage))
                {
                    Rsp.MessageFail("这项技能不能用做这种用途"); return Send(Rsp);
                }
                player.DaCommon.DictUsage[Req.Usage] = Req.Skill;
            }
            player.ActionSet();
            player.Hp();

            player.GetInfo(Rsp.DictUsage);
            player.GetInfo(Rsp.ListUsage);

            player.InfoBase();

            return Send(Rsp);
        }
    }
}
